var app = getApp();
Page({
    data: {
        Popanimation: true,
        commentpage: {
            isend: false,
            doing: false,
            doo: 'comment',
            pdata: {
                op: 'list',
                page: 2,
                gid: 0,
            },
            waitf: 0,
            nodataf: 0,
        },
        helppage: {
            isend: false,
            doing: false,
            doo: 'help',
            pdata: {
                op: 'list',
                page: 2,
                cid: 0,
            },
            waitf: 0,
            nodataf: 0,
        },
        swipheight: 320,
        groupmem: 0,
        isIPX: app.globalData.isIPX,
        isneedgetshare: true,
        bindgoods: [],
        popknow: false,
        bgmusic: false,
        closebg: false,
        good: {},
        footimg: {},
        iconPlayShow: true,
        maincolor: '',
        currentSwiper: 0,
        autoplay: true,
        isshowtags: false,
        isneedauth: false,
        showallfd: false,
        isshowgroup: false,
        isStick: false,
        labelstick: [],
        shoptop: 0,
        infotop: 0,
        knowtop: 0,
        commenttop: 0,
        studylist: [],
        givecard: [],
        nearlylog: [],
        showallfd: false,
        liveid: 0,
        isshowredbag: true,
        isshowgivecard: false,
        buynum: 1,
        isshowyyrule: false,
        yyrule: '',
        isshowifact: false,
        isshowific: false,
        showgetnum: false,
        fxrank: [],
        rankpage: 2,
        rulepic: '',
    },
    onShow: function () {
        var self = this;
        wx.hideTabBar();

        if (self.data.inited && self.data.good && self.data.good.type != 5) {
            app.com.http('good_v1', 'POST', {
                gid: self.data.good.id,
                op: 'iswaitpay'
            }, 0, false, '', '', function (res) {
                if (!res.data.errno && res.data) {
                    self.setData({
                        Popanimation: 1,
                        'good.isorder': res.data.data.isorder,
                        'good.waitorderid': res.data.data.waitorderid,
                        'good.waitpayurl': res.data.data.waitpayurl,
                    })
                }
            })
        }
        if (self.data.good.music && !self.data.closebg) {
            this.replaybg(1);
        }
    },
    onUnload() {
        if (this.data.bgmusic) {
            this.replaybg(2);
        }
    },
    onHide() {
        if (this.data.bgmusic) {
            this.replaybg(2);
        }
    },
    onLoad: function (options) {
        var self = this;
        if (options.scene) {
            var list = options.scene.split('_');
            options.id = list[0] ? list[0] : 0;
            options.zfid = list[1] ? list[1] : 0;
            options.cid = list[2] ? list[2] : 0;
        }

        var gid = options.id ? options.id : '';
        var shareid = options.shareid ? options.shareid : '';
        self.setData({
            options: options,
            zfid: options.zfid ? options.zfid : '',
            cid: options.cid ? options.cid : '',
            zfopenid: options.share_openid ? options.share_openid : '',
            'commentpage.pdata.gid': gid,
            shareid: shareid,
            groupid: options.groupid ? options.groupid : '',
            liveid: options.liveid ? options.liveid : '',
        });

        var loc = wx.getStorageSync('nlloc');
        loc = loc ? loc : {
            latitude: 0,
            longitude: 0
        };
        self.data.lat = loc.latitude;
        self.data.lng = loc.longitude;

        app.com.auth(function (user) {
            self.getData(options.id, loc.latitude, loc.longitude, false, function () {
                if (loc.latitude * 1 <= 0) {

                    app.com.getLocation(self, function (loc) {
                        self.setData({
                            lat: loc.latitude,
                            lng: loc.longitude,
                        });
                        self.getData(options.id, loc.latitude, loc.longitude, false);
                    })
                }
            });
        });

        clearInterval(self.data.timer);
    },
    getData(gid, lat, lng, hidestate, fn) {
        var self = this;
        var postdata = {
            gid: gid,
            op: 'info',
            lat: lat,
            lng: lng,
            cid: self.data.cid,
            zfid: self.data.zfid,
            shareid: self.data.shareid,
            hidestate: hidestate,
            groupid: self.data.groupid,
            isinit: self.data.good.id ? 1 : 0,
        };

        app.com.http('good_v1', 'POST', postdata, 0, false, '', '', function (res) {
            if (!res.data.errno && res.data) {

                self.setData({
                    good: res.data.data.good,
                    inited: true,
                })

                setTimeout(function () {
                    self.setData({
                        label: res.data.data.label,
                        labelstick: res.data.data.labelstick,
                        Tabcurrent: 'info',
                        isshowredbag: true,
                        shop: res.data.data.shop,
                        fendian: res.data.data.fendian,
                        params: res.data.data.params,
                        userinfo: res.data.data.userinfo,
                        InfoNonelist: res.data.data.more ? res.data.data.more : false,
                        groups: res.data.data.groups ? res.data.data.groups : false,
                        redbag: res.data.data.redbag ? res.data.data.redbag : false,
                        KansuccessPop: res.data.data.cut && res.data.data.cut.status == 1 && res.data.data.cut.ispay == 0 && res.data.data.cut.ismy == 1 ? true : false,
                        cut: res.data.data.cut ? res.data.data.cut : false,
                        lottery: res.data.data.lottery ? res.data.data.lottery : false,
                        lottlist: res.data.data.lottlist ? res.data.data.lottlist : false,
                        awardlist: res.data.data.awardlist ? res.data.data.awardlist : false,
                        rulestock: res.data.data.good.stock,

                        comment: res.data.data.comment,
                        allcard: res.data.data.allcard,
                        buyed: res.data.data.buyed ? res.data.data.buyed : false,
                        rule: res.data.data.good.rulearray ? res.data.data.good.rulearray.rule : {},
                        rulemap: res.data.data.good.rulearray ? res.data.data.good.rulearray.rulemap : {},
                        goodpak: res.data.data.goodpak ? res.data.data.goodpak : [],
                        tuijian: res.data.data.tuijian ? res.data.data.tuijian : [],
                        bindgoods: res.data.data.bindgoods ? res.data.data.bindgoods : [],
                        footimg: res.data.data.footimg ? res.data.data.footimg : {},
                        studylist: res.data.data.studylist ? res.data.data.studylist : [],
                        newuserlist: res.data.data.newuserlist ? res.data.data.newuserlist : [],
                        givecard: res.data.data.givecard ? res.data.data.givecard : [],
                        zcinfo: res.data.data.zcinfo ? res.data.data.zcinfo : {},
                        nearlylog: res.data.data.nearlylog ? res.data.data.nearlylog : [],
                        fxrank: res.data.data.fxrank ? res.data.data.fxrank : [],
                        rankpage: 2,
                        isneedauth: res.data.data.params.needauth == 1 ? true : false,
                    }, function () {
                        if (fn) fn();
                        if (res.data.data.sharedata) {
                            self.setData({
                                sharedata: res.data.data.sharedata,
                                isneedgetshare: false,
                                isshowgroup: self.data.groups.length > 0 ? true : false,
                                showuserbtn: res.data.data.params.mustauth == 1 ? true : false,
                            })
                        }
                        if (res.data.data.params.mustauth == 1) {
                            self.selectComponent('#authbtn').showauth();
                        }

                        self.swiperchange();

                        if (!hidestate && self.data.cid && res.data.data.cut && !res.data.data.cut.ismy) {
                            self.helpit();
                        }

                        // 自动参与
                        if (!hidestate && self.data.good.type == 5 && self.data.good.isopenlott == 0 && self.data.good.over_type == 0) {
                            if (self.data.lottery.status == 0) {
                                self.joinLottery();
                            }
                            if (self.data.lottery.status == 1 && self.data.good.chousmaxs > 0) {
                                self.setData({
                                    tipshare: true
                                });
                            }
                        }

                        if (res.data.data.good.video) {
                            app.com.http('gettenvedio', 'POST', {
                                url: res.data.data.good.video
                            }, 0, false, '', '', function (resa) {
                                var dataset = 'good.vediourl';
                                self.setData({
                                    [dataset]: !res.data.message.errno ? resa.data.message : res.data.data.good.video
                                });
                            })
                        }

                        if (self.data.good.thisgroupmember > 0) {
                            self.jingroupstart(self.data.good.thisgroupmember, self.data.good.thisgroupprice);
                        }

                        self.setData({
                            maincolor: app.com.mainColor(res.data.data.params.style),
                        })

                    });

                    if (self.data.good.music) {
                        self.playbg();
                    }

                }, 5);

                setTimeout(function () {
                    if (res.data.data.good.content) {
                        self.setData({
                            loadinfo: true,
                        })
                        setTimeout(function () {
                            var octoparse = require('../../resource/wxParse/html2json2.js');
                            var transData = octoparse.parse(res.data.data.good.content);
                            self.setData({
                                nodes: transData,
                                loadinfo: false,
                            })
                        }, 100)
                    }
                    if (res.data.data.good.shopinfo) {
                        var octoparse = require('../../resource/wxParse/html2json2.js');
                        var transData = octoparse.parse(res.data.data.good.shopinfo);
                        self.setData({
                            shopnodes: transData,
                        })
                    }
                    if (res.data.data.yyrule) {
                        var octoparse = require('../../resource/wxParse/html2json2.js');
                        var transData = octoparse.parse(res.data.data.yyrule);
                        self.setData({
                            yyrule: transData,
                        })
                    }


                    wx.setNavigationBarTitle({
                        title: res.data.data.good.title,
                    });

                    self.data.timer = false;
                    self.endTime();

                    // 再获取一次
                    setTimeout(function () {
                        self.getShare();
                    }, 4000)

                }, 5);

            } else {
                app.com.alert(res.data.message, function () {
                    app.com.backPage(self.data.options.zfid);
                });
            }
        });
    },
    endTime() {
        var self = this;
        if (self.data.timer) return false;
        self.countTime();

        self.data.timer = setInterval(function () {
            self.countTime();
        }, 1000);

    },
    countTime() {
        var self = this;
        var date = new Date();
        var time = date.getTime();
        if (self.data.groups.length > 0) {
            for (var i = 0; i < self.data.groups.length; i++) {
                var item = self.data.groups[i];
                var endTime = item.end + '000';
                var lag = (endTime * 1 - time);
                if (lag > 0) {
                    var second = Math.floor(lag / 1000 % 60);
                    var minite = Math.floor(lag / 1000 / 60 % 60);
                    var hour = Math.floor(lag / 1000 / 60 / 60 % 24);
                    var day = Math.floor(lag / 1000 / 60 / 60 / 24);
                } else {
                    var second = '0';
                    var minite = '0';
                    var hour = '0';
                    var day = '0';
                }
                self.setData({
                    ['groups[' + i + '].time']: {
                        day: day,
                        hour: hour,
                        minite: minite,
                        second: second
                    }
                });
            }
        }

        var endTime = 0;
        if (self.data.good.over_type == 0) {
            endTime = self.data.good.end + '000';
        }
        if (self.data.good.over_type == 2) {
            endTime = self.data.good.start + '000';
        }

        if (self.data.good.over_type == 0 && self.data.cut && self.data.cut.status == 0 && self.data.cut.endtime > time / 1000) {
            endTime = self.data.cut.endtime + '000';
        }

        if (self.data.good.type != 0 && endTime != 0 && self.data.good.isopenlott != 1) {

            var lag = (endTime * 1 - time);
            if (lag > 0) {
                var second = Math.floor(lag / 1000 % 60);
                var minite = Math.floor(lag / 1000 / 60 % 60);
                var hour = Math.floor(lag / 1000 / 60 / 60 % 24);
                var day = Math.floor(lag / 1000 / 60 / 60 / 24);
            } else {
                var second = 0;
                var minite = 0;
                var hour = 0;
                var day = 0;
                if (self.data.good.over_type == 0) {
                    self.setData({
                        'good.over_type': 3,
                    });
                } else if (self.data.good.over_type == 2) {
                    self.setData({
                        'good.over_type': 0,
                    });
                }

            }
            self.setData({
                Countdown: {
                    day: day,
                    hour: hour,
                    minute: minite,
                    second: second
                }
            });
        }
    },
    onPullDownRefresh: function () {
        if (this.data.isdown) return false;
        this.setData({
            SharePopupshow: false,
            hideInfoNone: false,
        })

        this.data.isdown = true;
        this.onLoad(this.data.options);
        this.data.isdown = false;

        wx.stopPullDownRefresh();
    },
    onShareAppMessage: function (e) {
        var self = this;
        if (e.from == 'button' && e.target.dataset.type * 1 == 11) {
            return {
                title: self.data.sharedata.title,
                path: '/zofui_sales/comment/info?id=' + e.target.dataset.id,
                imageUrl: self.data.sharedata.img,
            }
        } else {
            return {
                title: self.data.sharedata.title,
                path: self.data.sharedata.path,
                imageUrl: self.data.sharedata.img,
            }
        }
    },
    onShareTimeline() {
        return {
            title: this.data.sharedata.title,
            query: this.data.sharedata.query,
            imageUrl: this.data.sharedata.img,
        }
    },
    getShare() {
        var self = this;
        if (!self.data.isneedgetshare) return false;
        app.com.auth(function (user) {
            app.com.http('user_v1', 'POST', {
                gid: self.data.good.id,
                op: 'getshare'
            }, 0, true, '', '', function (res) {
                if (!res.data.errno && res.data) {
                    self.setData({
                        sharedata: res.data.data.sharedata,
                        isneedgetshare: false,
                    })
                }
            })
        })
    },
    hidepopknow() {
        this.setData({
            popknow: false
        })
    },
    popknowfn() {
        if (this.data.poptype == 1) {
            var e = {
                currentTarget: {
                    dataset: {
                        type: this.data.popbuytype
                    }
                }
            };
            this.buyit(e);
        } else if (this.data.poptype == 2) {
            this.joincut();
        } else if (this.data.poptype == 3) {
            this.sublott();
        }
        this.setData({
            popknow: false,
        })
    },
    hidegroups() {
        this.setData({
            isshowgroup: false
        })
    },
    buyit(e) {
        var self = this
        if (this.data.isneedauth) {
            this.setData({
                buye: e,
                authtype: 'buy',
                showuserbtn: true,
            })
            this.selectComponent('#authbtn').hideauth();
            return false;
        }

        var type = e.currentTarget.dataset.type ? e.currentTarget.dataset.type : 0;
        if (this.data.good.tips && this.data.good.popknow == 1 && !this.data.popknow) {
            this.setData({
                popknow: true,
                poptype: 1,
                popbuytype: type,
            })
            return false;
        }

        // 存在订单
        if (this.data.good.isorder == 1) {
            this.setData({
                Popanimation: true
            });
            return false;
        }
        if (this.data.good.isinsever == 0) {
            app.com.toast('不在销售范围内');
            return false;
        }
        if (this.data.good.isintime == 0) {
            app.com.toast('不在下单时间内');
            return false;
        }

        if (this.data.good.isrule == 1) {
            this.setData({
                showrule: true,
                showruletype: 'buy',
                buytype: type,
            });
        } else {
            // 0正常购买 1拼团
            wx.setStorageSync('zfssbuy', {
                gid: this.data.good.id,
                type: type,
                num: this.data.buynum,
                groupid: this.data.groupid,
                groupmem: this.data.groupmem,
                liveid: this.data.liveid,
            });

            if (this.data.good.getnum * 1 > 0) {
                this.setData({
                    showgetnum: true,
                })
            } else {
                if (this.data.good.istoshop != 1) {
                    self.cartjs()
                } else {
                    var tourl = '/zofui_sales/order/confirm';
                    wx.navigateTo({
                        url: tourl
                    });
                }

            }
        }
        this.subMess();
    },
    
    cartjs(){
        var self = this;

        app.com.getLocation(self,function(loc){
            app.com.auth(function(user){
                var cache = wx.getStorageSync('zfssbuy');
                if( !cache || cache == "" ){
                    //wx.navigateBack();
                }else{
                    var postdata = {
                        op : 'info',
                        gid : cache.gid ? cache.gid : 0,
                        cid : cache.cid ? cache.cid : 0,
                        num : cache.num ? cache.num : 1,
                        groupid : cache.groupid ? cache.groupid : 0,
                        cartlist : cache.arr ? JSON.stringify( cache.arr ) : [],
                        type : cache.type,
                        mapid : cache.mapid,
                        groupmem : cache.groupmem ? cache.groupmem : '',
                        addcart : 1,
                        lat : (loc.latitude ? loc.latitude : 0),
                        lng : (loc.longitude ? loc.longitude : 0),
                        ischangeadd : 0,
                    };
                    self.data.lat = postdata.lat;
                    self.data.lng = postdata.lng;

                    app.com.http('confirmv1_v1','POST',postdata,0,false,'','',function(res){
                        if(!res.data.errno  && res.data){
                            let orderdata = {
                                isusejifen : 0,
                                jifendis : 0,
                                params : res.data.data.params,
                                goodlist : res.data.data.goodlist ? res.data.data.goodlist : [],
                                userinfo : res.data.data.userinfo,
                                name : res.data.data.params.ordername,
                                tel : '123',
                                pcard : res.data.data.params.orderpcard,
                                num : 1,
                                buytype : cache.type,
                                mapid : cache.mapid,
                                groupmem : cache.groupmem ? cache.groupmem : 0,
                                mapname : cache.mapname ? cache.mapname : '',
                                groupid : cache.groupid ? cache.groupid : 0,
                                liveid : cache.liveid ? cache.liveid : '',
                                cid : cache.cid ? cache.cid : 0,
                                inited : true,
                                allcard : res.data.data.allcard ? res.data.data.allcard : [],
                                taketype : res.data.data.params.taketype,
                                paytype : res.data.data.params.paytype,
                                myredbag : res.data.data.myredbag ? res.data.data.myredbag : false,
                                form : res.data.data.form ? res.data.data.form : false,
                                ctaddress :  res.data.data.userinfo.ctyaddress ? res.data.data.userinfo.ctyaddress : '',
                                ctyarea : res.data.data.myaddress ? res.data.data.myaddress.ctyarea : '',
                            }
                            if(postdata.ischangeadd == 0){
                                orderdata['aname']  = res.data.data.myaddress ? res.data.data.myaddress.name : ''
                                orderdata['address'] =  res.data.data.myaddress ? res.data.data.myaddress.address : ''
                                orderdata['lat'] =  res.data.data.myaddress ? res.data.data.myaddress.lat : self.data.lat
                                orderdata['lng'] =  res.data.data.myaddress ? res.data.data.myaddress.lng : self.data.lng
                            }
                            self.confirm(orderdata)
                        }else if( res.data.errno == 2 ){
                            app.com.alert('你还有未支付的订单，请先支付',function(){
                                wx.setStorageSync('zfssbuy','');
                                var tourl = '/zofui_sales/order/orderinfo?id='+res.data.data.orderid;
                                wx.navigateTo({
                                  url: tourl
                                });
                            });
                        }else if( res.data.errno == 3 ){
                            app.com.confirm(res.data.message,function(){
                                wx.setStorageSync('zfssbuy','');
                                var tourl = '/zofui_sales/ucard/buycard';
                                wx.navigateTo({
                                  url: tourl
                                });
                            },function(){
                                wx.navigateBack();
                            },'取消','购买会员');
                        }else{
                            app.com.alert(res.data.message,function(){
                                wx.navigateBack();
                            });
                        }
                    })
                }
            });
        })

    },
    
    confirm(orderdata){
    	var self = this;
    	var subform = [];
        var goodlist = [];
        for (var i = 0; i < orderdata.goodlist.length; i++) {
            var item = orderdata.goodlist[i];
            var into = { cardid : item.cardid ,yhmcode:item.yhmcode, list : [] };
            for (var j = 0; j < item.list.length; j++) {
                into.list.push({
                    id : item.list[j].id,
                    gid : item.list[j].gid,
                    num : item.list[j].num,
                    redid : item.list[j].redbagid,
                    yydate : item.list[j].yydate ? item.list[j].yydate : '',
                    yytime : item.list[j].yytime ? item.list[j].yytime : '',
                    toshopid : item.list[j].toshopid ? item.list[j].toshopid : '',
                    oname : item.list[j].oname ? item.list[j].oname : '',
                });
            }
            goodlist.push(into);
        }

        var pidarr = wx.getStorageSync('tclist');

        var postdata = {
            op:'pay',
            taketype : orderdata.taketype,
            paytype : orderdata.paytype,
            name:orderdata.name,
            tel:orderdata.tel,
            pcard : orderdata.pcard,
            mess : orderdata.mess,
            num : orderdata.num,
            buytype : orderdata.buytype,
            groupid : orderdata.groupid,
            cid : orderdata.cid,
            aname : orderdata.aname,
            atel : '',
            province : orderdata.province ? orderdata.province : '',
            city : orderdata.city ? orderdata.city : '',
            country : orderdata.country ? orderdata.country : '',
            address : orderdata.address,
            ctyarea : orderdata.ctyarea ? orderdata.ctyarea : '',
            liveid : orderdata.liveid ? orderdata.liveid : '',
            cardid : orderdata.cardid,
            isusejifen : orderdata.isusejifen ? orderdata.isusejifen : 0,
            jifendis : orderdata.jifendis > 0 ? orderdata.jifendis : 0,
            ctaddress : orderdata.ctaddress ? orderdata.ctaddress : '',
            groupmem : orderdata.groupmem ? orderdata.groupmem : 0,
            mapid : orderdata.mapid ? orderdata.mapid : '',
            addcart : 1,// 新版的
            goodlist : goodlist ? JSON.stringify( goodlist ) : [],
            subform : subform ? JSON.stringify( subform ) : 0,
            lat : orderdata.lat,
            lng : orderdata.lng,
            pidarr : pidarr ? JSON.stringify( pidarr ) : [],
            paynumber : orderdata.paynumber ? orderdata.paynumber : '',
            paycid : orderdata.paycid ? orderdata.paycid : '',
        };
        
        if( orderdata.payed ) return false;
        orderdata.payed = true;

        app.com.http('confirmv1_v1','POST',postdata,0,true,'','',function(res){
            orderdata.payed = false;
            if (!res.data.errno && res.data) {
                wx.setStorageSync('zfssbuy','');
                if( res.data.data.payed == 1 ){
                    self.paysuc(res.data.data,orderdata.buytype);
                    if( res.data.data.channel ){
                        app.com.sendGo(res.data.data.gomess,res.data.data.channel);
                    }
                }else{
                    self.setData({ // 防止返回商品
                        isback : false,
                    })
                    wx.requestPayment({
                        'appId' : res.data.data.appId,
                        'timeStamp': res.data.data.timeStamp,
                        'nonceStr': res.data.data.nonceStr,
                        'package': res.data.data.package,
                        'signType': 'MD5',
                        'paySign': res.data.data.paySign,
                        'success': function (payres) {
                            if( payres.errMsg == 'requestPayment:ok' ){
                                self.paysuc(res.data.data,orderdata.buytype);
                                if( res.data.data.channel ){
                                    app.com.sendGo(res.data.data.gomess,res.data.data.channel);
                                }
                            }
                        },
                        'fail': function (payres) {
                            var tip = orderdata.params.fontsty == 33 ? '请尽快提交' : '请尽快支付';

                            app.com.toast(tip,'fail',function(){
                                var tourl = '/zofui_sales/order/orderinfo?id='+res.data.data.orderid;
                                if( orderdata.buytype == 'cart' ) {
                                    tourl = '/zofui_sales/order/orderlist?dealid'+res.data.data.orderid;
                                    if(orderdata.params.shopnav*1 == 1){
                                        tourl += '?shopid='+orderdata.goodlist[0].shopid;
                                    }
                                }
                                wx.navigateTo({
                                    url: tourl,
                                    complete : function(){
                                        self.setData({
                                            isback : true,
                                        })
                                    }
                                });

                            });
                        }
                    });
                }
            }else{
            	app.com.alert(res.data.message);
            }
        });
    	
    },
    togglerule() {
        this.setData({
            showrule: false,
        });
    },
    hidetcnum() {
        this.setData({
            showgetnum: false,
        });
    },
    showyyrule() {
        this.setData({
            isshowyyrule: true,
        })
    },
    hideyyrule() {
        this.setData({
            isshowyyrule: false,
        })
    },
    changeRule(e) {
        var self = this;
        for (var i = 0; i < self.data.rule.length; i++) {
            if (self.data.rule[i].pro.id == e.currentTarget.dataset.oid) {
                var target = 'rule[' + i + '].actitem';
                self.setData({
                    [target]: e.currentTarget.dataset.tid,
                });

                var selectarr = [];

                for (var j = 0; j < self.data.rule.length; j++) {
                    if (self.data.rule[j].actitem) {
                        selectarr.push(self.data.rule[j].actitem);
                    }
                }
                if (selectarr.length < self.data.rule.length) return false;

                for (var j = 0; j < self.data.rulemap.length; j++) {
                    var thisstr = (self.data.rulemap[j].id + '').split(":");
                    if (thisstr.sort().toString() == selectarr.sort().toString()) {

                        var ruleprice =
                            self.data.buytype == 3 || self.data.buytype == 0 || !self.data.buytype || self.data.buytype == 6 ?
                            (self.data.userinfo.level == 1 ? self.data.rulemap[j].uprice : self.data.rulemap[j].nowprice) :
                            (self.data.userinfo.level == 1 ? self.data.rulemap[j].ugprice : self.data.rulemap[j].groupprice);

                        self.setData({
                            rulestock: self.data.rulemap[j].stock,
                            rulepic: self.data.rulemap[j].pic ? self.data.rulemap[j].pic : '',
                            buynum: self.data.buynum > self.data.rulemap[j].stock ? self.data.rulemap[j].stock : self.data.buynum,
                            rulefee: ruleprice,
                            actmap: self.data.rulemap[j].id,
                            mapname: self.data.rulemap[j].name,
                        });

                        return false;
                    }
                }
                return false;
            }
        }
    },
    confirmrule() {
        var self = this;
        if (self.data.good.isrule == 1) {
            for (var i = 0; i < self.data.rule.length; i++) {
                if (!self.data.rule[i].actitem || typeof self.data.rule[i].actitem == 'undefined') {
                    app.com.toast('请选择' + self.data.rule[i].pro.title);
                    return false;
                }
            }
        }
        if (!self.data.actmap || !self.data.mapname) {
            app.com.toast('请选择下单类型');
            return false;
        }

        wx.setStorageSync('zfssbuy', {
            gid: this.data.good.id,
            type: self.data.buytype,
            num: self.data.buynum,
            mapid: self.data.actmap,
            mapname: self.data.mapname,
            groupid: self.data.groupid,
            liveid: self.data.liveid
        });
        var tourl = '/zofui_sales/order/confirm';
        wx.navigateTo({
            url: tourl
        });
    },
    joincut() {
        var self = this;

        if (this.data.isneedauth) {
            this.setData({
                authtype: 'cut',
                showuserbtn: true,
            })
            this.selectComponent('#authbtn').hideauth();
            return false;
        }

        if (this.data.good.isinsever == 0) {
            app.com.toast('不在销售范围内');
            return false;
        }
        if (this.data.good.isintime == 0) {
            app.com.toast('不在下单时间内');
            return false;
        }

        if (this.data.good.tips && this.data.good.popknow == 1 && !this.data.popknow) {
            this.setData({
                popknow: true,
                poptype: 2,
            })
            return false;
        }

        app.com.http('cut', 'POST', {
            gid: self.data.good.id,
            op: 'join'
        }, 0, true, '', '', function (res) {
            if (!res.data.errno && res.data) {
                self.setData({
                    cut: res.data.data.cut,
                    HelpkanInfo: true,
                    helpkantxt: res.data.data.downinfo.txt,
                    'sharedata.path': '/zofui_sales/pages/good/good?id=' + self.data.good.id + '&zfid=' + self.data.userinfo.id + '&cid=' + res.data.data.cut.id
                })
            } else if (res.data.errno == 3) {
                app.com.confirm(res.data.message, function () {
                    wx.setStorageSync('zfssbuy', '');
                    var tourl = '/zofui_sales/ucard/buycard';
                    wx.navigateTo({
                        url: tourl
                    });
                }, false, '取消', '购买会员');
            } else {
                app.com.toast(res.data.message);
            }
        })
        self.subMess();
    },
    helpit() {
        var self = this;
        app.com.http('cut', 'POST', {
            cid: self.data.cut.id,
            op: 'help'
        }, 0, true, '', '', function (res) {
            if (!res.data.errno && res.data) {
                self.setData({
                    HelpkanInfo: true,
                    helpkantxt: res.data.data.downinfo.txt,
                })
            } else {
                app.com.toast(res.data.message);
            }
        })
        self.subMess();
    },
    kanInfoclose() {
        this.setData({
            HelpkanInfo: false,
        })
    },
    bindCollect() {
        var self = this;
        app.com.http('good_v1', 'POST', {
            gid: self.data.good.id,
            op: 'collect'
        }, 0, true, '', '', function (res) {
            if (res.data.errno == 2) {
                app.com.toast(res.data.message);
                self.setData({
                    'good.iscollect': true
                });
            } else if (res.data.errno == 3) {
                app.com.toast(res.data.message);
                self.setData({
                    'good.iscollect': false
                });
            } else {
                app.com.toast(res.data.message);
            }
        })
    },
    openShareArea: function (e) {
        var self = this;
        self.setData({
            SharePopupshow: !self.data.SharePopupshow
        })
        setTimeout(function () {
            self.setData({
                shareVisible: self.data.SharePopupshow ? 'visible' : ''
            })
        }, 300)
        if (self.data.SharePopupshow && !self.data.posterurl) {
            self.getPoster(1);
        }
    },
    closeInfoNone() {
        this.setData({
            hideInfoNone: true,
        })
    },
    toggleDetail() {
        this.setData({
            showDetail: !this.data.showDetail,
        })
    },
    tabChange: function (e) {
        var self = this;
        var type = e.currentTarget.dataset.type * 1;
        var index = e.currentTarget.dataset.index;
        if (index != 'know' && index != 'shopt' && index != 'commentt') {
            self.setData({
                Tabcurrent: index,
            })
        }
        self.setData({
            Tabcurrentl: index,
        })
        var query = wx.createSelectorQuery();
        if (type == 1) {
            var top = 0;
            if (index == 'shopt') {
                query.select('#shoptop').boundingClientRect()

            } else if (index == 'know') {
                query.select('#knowtop').boundingClientRect()
            } else if (index == 'info') {
                query.select('#infotop').boundingClientRect()
            } else if (index == 'comment') {
                query.select('#infotop').boundingClientRect()
            } else if (index == 'commentt') {
                query.select('#commenttop').boundingClientRect()
            }

            query.exec(function (res) {
                top = self.data.sctop + res[0].top;
                wx.pageScrollTo({
                    scrollTop: top,
                    duration: 100
                });
            })

        }

    },
    InfoOrderpayPop() {
        this.setData({
            Popanimation: false,
        })
    },
    cancelOrder() {
        var self = this;
        app.com.http('good_v1', 'POST', {
            oid: self.data.good.waitorderid,
            op: 'cancel'
        }, 0, true, '', '', function (res) {
            app.com.toast(res.data.message);
            if (!res.data.errno && res.data) {
                self.setData({
                    'good.isorder': 0
                })
            }
        })
    },
    KansuccessPopclose() {
        var self = this;
        self.setData({
            KansuccessPop: false
        })
    },
    KansuccessPopkanpay() {
        var self = this;
        // 4 砍价订单
        wx.setStorageSync('zfssbuy', {
            cid: this.data.cut.id,
            type: 4,
            liveid: this.data.liveid,
        });
        var tourl = '/zofui_sales/order/confirm';
        wx.navigateTo({
            url: tourl
        });
    },
    morecomment() {
        var self = this;
        app.com.getPage(self, self.data.commentpage, 20, function (res) {
            if (res.data.data.list.length > 0) {
                self.setData({
                    comment: self.data.comment.concat(res.data.data.list)
                });
            } else {
                self.setData({
                    commented: true
                });
            }
        }, false, false, 'commentpage');
    },
    morehelp() {
        var self = this;
        self.setData({
            'helppage.pdata.cid': self.data.cut.id
        });
        app.com.getPage(self, self.data.helppage, 20, function (res) {
            if (res.data.data.list.length > 0) {
                self.setData({
                    'cut.helplist': self.data.cut.helplist.concat(res.data.data.list)
                });
            } else {
                self.setData({
                    helplisted: true
                });
            }
        }, false, false, 'helppage');
    },
    givefriend() {
        var self = this;
        if (!wx.openBusinessView) {
            app.com.alert('微信版本低，不支持此功能');
            return false;
        }
        if (self.data.good.ishwq == 0 || !self.data.good.ishwq) {
            app.com.http('good_v1', 'POST', {
                op: 'tuijian',
                gid: self.data.good.id
            }, 0, true, '', '', function (res) {
                if (!res.data.errno && res.data) {
                    self.openBusinessView();
                } else {
                    app.com.toast(res.data.message);
                }
            });
        } else {
            self.openBusinessView();
        }
    },
    openBusinessView() {
        var self = this;
        if (!wx.openBusinessView) {
            app.com.alert('微信版本低，不支持此功能');
            return false;
        }
        wx.openBusinessView({
            businessType: 'friendGoodsRecommend',
            extraData: {
                product: {
                    item_code: self.data.good.id,
                    title: self.data.good.title,
                    image_list: self.data.good.img
                }
            },
            success: function (res) {
                //app.com.toast('成功推荐到你的好物圈');
            },
            fail: function (res) {
                //app.com.alert('推荐失败');
            }
        })
    },
    getPoster(e) {
        var self = this;

        if (this.data.isneedauth) {
            this.setData({
                authtype: 'poster',
                showuserbtn: true,
            })
            this.selectComponent('#authbtn').hideauth();
            return false;
        }

        app.com.http('poster', 'POST', {
            op: 'goods',
            gid: self.data.good.id,
            path: self.data.sharedata.path
        }, 0, true, '', '', function (res) {
            if (!res.data.errno && res.data) {
                self.setData({
                    posterurl: res.data.data.url
                });
                if (e != 1) {
                    app.com.alert('可长按图片保存到本地相册和发给好友！', function () {
                        wx.previewImage({
                            urls: [res.data.data.url]
                        })
                    });
                }
            } else {
                app.com.toast(res.data.message);
            }
        });
    },
    posterurl() {
        wx.previewImage({
            urls: [this.data.posterurl]
        })
    },
    saveposter() {
        var self = this;
        wx.downloadFile({
            url: self.data.posterurl,
            success: function (res) {
                wx.saveImageToPhotosAlbum({
                    filePath: res.tempFilePath,
                    success(res) {
                        app.com.toast('已保存到本地相册');
                    },
                    fail(res) {
                        app.com.toast('保存失败');
                    }
                })
            },
            fail: function (res) {
                app.com.toast('下载文件失败');
            }
        })
    },
    joinLottery() {
        this.setData({
            choupop: true
        })
    },
    lotttel(e) {
        this.setData({
            'userinfo.tel': e.detail.value
        })
    },
    lottname(e) {
        this.setData({
            'userinfo.name': e.detail.value
        })
    },
    lottadd(e) {
        this.setData({
            'userinfo.address': e.detail.value
        })
    },
    sublott() {
        var self = this;
        var name = '';
        if (this.data.isneedauth) {
            this.setData({
                authtype: 'lott',
                showuserbtn: true,
            })
            this.selectComponent('#authbtn').hideauth();
            return false;
        }

        var tel = self.data.userinfo.tel;
        if (this.data.good.isinsever == 0) {
            app.com.toast('不在可参与范围内');
            return false;
        }
        if (!tel || !app.com.verify('mobile', tel)) {
            app.com.toast('请填写正确的联系电话');
            return false;
        }
        if (!self.data.userinfo.name && self.data.good.isexpress == 1) {
            app.com.toast('请填写姓名');
            return false;
        }
        if (!self.data.userinfo.address && self.data.good.isexpress == 1) {
            app.com.toast('请填写地址');
            return false;
        }


        if (this.data.good.tipsknow && this.data.good.popknow == 1 && !this.data.popknow) {
            this.setData({
                popknow: true,
                poptype: 3,
            })

            return false;
        }

        if (self.data.good.chouprice > 0 && !self.data.ispayed) {

            var postdata = {
                op: 'payjoin',
                gid: self.data.good.id
            }

            app.com.http('lottery', 'POST', postdata, 0, true, '', '', function (res) {
                if (!res.data.errno && res.data) {
                    wx.setStorageSync('zfssbuy', '');
                    if (res.data.data.payed == 1) {
                        self.sublottfn(name, tel);
                    } else {
                        self.setData({ // 防止返回商品
                            isback: false,
                        })
                        wx.requestPayment({
                            'appId': res.data.data.appId,
                            'timeStamp': res.data.data.timeStamp,
                            'nonceStr': res.data.data.nonceStr,
                            'package': res.data.data.package,
                            'signType': 'MD5',
                            'paySign': res.data.data.paySign,
                            'success': function (payres) {
                                if (payres.errMsg == 'requestPayment:ok') {
                                    self.checkLottPay(name, tel);
                                }
                            },
                            'fail': function (payres) {

                            }
                        });
                    }
                } else {
                    self.data.payed = false;
                    app.com.alert(res.data.message);
                }
            });

        } else {
            self.sublottfn(name, tel);
        }
    },
    checkLottPay(name, tel) {
        var self = this;
        if (self.data.ispayed) return false;
        wx.showLoading({
            mask: true,
            title: '处理中'
        });
        setTimeout(function () {
            var postdata = {
                op: 'ispayed',
                gid: self.data.good.id,
            }
            app.com.http('lottery', 'POST', postdata, 0, false, '', '', function (res) {
                if (!res.data.errno && res.data) {
                    self.setData({
                        ispayed: 1,
                    });
                    self.sublottfn(name, tel);
                    wx.hideLoading();
                } else if (res.data.errno == 1) {
                    self.checkLottPay(name, tel);
                }
            });
        }, 1500);
    },
    sublottfn(name, tel) {
        var self = this;
        var postdata = {
            op: 'join',
            gid: self.data.good.id,
            name: name ? name : '',
            tel: tel ? tel : '',
            addname: self.data.userinfo.name,
            address: self.data.userinfo.address,
            inviteid: self.data.zfid,
            lat: self.data.lat ? self.data.lat : '',
            lng: self.data.lng ? self.data.lng : '',
        }
        if (this.data.good.isinsever == 0) {
            app.com.toast('不在可参与范围内');
            return false;
        }
        if (!postdata.tel || !app.com.verify('mobile', postdata.tel)) {
            app.com.toast('请填写正确的联系电话');
            return false;
        }
        if (!postdata.addname && self.data.good.isexpress == 1) {
            app.com.toast('请填写姓名');
            return false;
        }
        if (!postdata.address && self.data.good.isexpress == 1) {
            app.com.toast('请填写地址');
            return false;
        }

        app.com.http('lottery', 'POST', postdata, 0, true, '', '', function (res) {
            if (!res.data.errno && res.data) {
                self.data.lottery.list.push(res.data.data.code);
                self.setData({
                    'lottery.status': 1,
                    'good.join': self.data.good.join++,
                    'lottery.list': self.data.lottery.list,
                    choupop: false,
                    tipshare: true,
                    choupaktips: res.data.data.choupaktips ? res.data.data.choupaktips : false,
                });
                if (res.data.data.isopen == 1) {
                    self.onLoad(self.data.options);
                }
            } else if (res.data.errno == 3) {
                app.com.confirm(res.data.message, function () {
                    wx.setStorageSync('zfssbuy', '');
                    var tourl = '/zofui_sales/ucard/buycard';
                    wx.navigateTo({
                        url: tourl
                    });
                }, false, '取消', '购买会员');
            } else {
                app.com.toast(res.data.message);
            }
            app.subform();
        });

        self.subMess();
    },
    choupop() {
        this.setData({
            choupop: !this.data.choupop
        })
    },
    getPhoneNumber(e) {
        var self = this;
        if (e.detail.errMsg == 'getPhoneNumber:ok') {
            var postdata = {
                iv: e.detail.iv,
                encryptedData: e.detail.encryptedData,
                op: 'encrypt'
            };
            app.com.http('user_v1', 'POST', postdata, 0, true, '', '', function (res) {
                if (!res.data.errno) {
                    self.setData({
                        'userinfo.tel': res.data.data,
                    });
                } else {
                    app.com.alert(res.data.message);
                }
            });
        } else {
            app.com.alert('请允许授权');
        }
    },
    lookmore() {
        this.setData({
            reservations: !this.data.reservations
        })
    },
    tipshare() {
        this.setData({
            tipshare: !this.data.tipshare
        })
    },
    takecard(e) {
        var self = this;
        var postdata = {
            op: 'takecard',
            id: e.currentTarget.dataset.id,
        };
        app.com.http('card', 'POST', postdata, 0, true, '', '', function (res) {

            if (!res.data.errno && res.data) {
                app.com.toast(res.data.message);
                for (var i = 0; i < self.data.allcard.length; i++) {
                    if (self.data.allcard[i].id == postdata.id) {
                        self.setData({
                            ['allcard[' + i + '].istaked']: 1,
                        });
                        return false;
                    }
                }

            } else if (res.data.errno == 2) {
                app.com.confirm(res.data.message, function () {
                    var tourl = '/zofui_sales/ucard/buycard';
                    wx.navigateTo({
                        url: tourl
                    });
                }, false, '取消', '购买会员');
            } else if (res.data.errno == 5) {
                wx.navigateTo({
                    url: '/zofui_sales/card/info?id=' + postdata.id
                });
            } else {
                app.com.toast(res.data.message);
            }
        });
    },
    showVideo() {

        if (this.data.showVideo) {
            this.data.cvedio.stop();
        } else {
            this.data.cvedio = wx.createVideoContext('myVideo');
            this.data.cvedio.play();
        }

        this.setData({
            showVideo: !this.data.showVideo
        })
    },
    showqun() {
        this.setData({
            showqun: !this.data.showqun
        })
    },
    jingroupstart(mem, price) {
        var e = {
            currentTarget: {
                dataset: {
                    m: mem,
                    price: price,
                }
            },
            pass: 1,
        }
        this.getGroupprice(e);
    },
    getGroupprice(e) {
        if (this.data.options.from == 'group' && !e.pass) {
            return false;
        }
        this.setData({
            groupmem: e.currentTarget.dataset.m,
            'good.groupmem': e.currentTarget.dataset.m,
            'good.show_price.gprice': e.currentTarget.dataset.price,
        })
    },
    location: function (e) {
        app.com.location(e);
    },
    otherapp: function (e) {
        app.com.otherapp(e);
    },
    navigateto: function (e) {
        app.com.navigateto(e);
    },
    switchTab(e) {
        if (this.data.bgmusic) {
            this.data.bgmusic.destroy();
        }
        wx.switchTab({
            url: e.currentTarget.dataset.url
        });
    },
    back() {
        wx.navigateBack();
    },
    redirectto: function (e) {
        app.com.redirectto(e);
    },
    callphone: function (e) {
        app.com.callphone(e);
    },
    toweburl: function (e) {
        app.com.toweburl(e);
    },
    showimages: function (e) {
        app.com.showimages(e);
    },
    preimg: function (e) {
        wx.previewImage({
            urls: e.currentTarget.dataset.img
        });
    },
    FormIdsubmit: function (e) {
        if (app.globalData.formarr.length <= 50) app.globalData.formarr.push(e.detail.formId);
    },
    imageLoad: function (e) {
        var self = this;
        //获取图片真实宽度  
        var imgwidth = e.detail.width,
            imgheight = e.detail.height;
        //宽高比
        var ratio = 1;
        wx.getSystemInfo({
            success: function (res) {
                ratio = res.windowWidth / imgwidth;
            }
        });
        var viewHeight = imgheight * ratio;
        self.setData({
            swipheight: viewHeight,
        });
    },
    updateUserInfo: function (e) {
        var self = this;
        app.com.getUserInfo(function (res) {
            self.setData({
                showuserbtn: false,
                isneedauth: false,
            });
            self.authfn();
        }, false, e.detail);
    },
    hideauth() {
        this.setData({
            isneedauth: false,
            showuserbtn: false,
        });
        this.authfn();
    },
    authfn() {
        console.log('1')
        this.setData({
            isneedauth: false,
            showuserbtn: false,
        });
        if (this.data.authtype == 'buy') {
            this.buyit(this.data.buye);
        } else if (this.data.authtype == 'poster') {
            this.getPoster();
        } else if (this.data.authtype == 'lott') {
            this.sublott();
        } else if (this.data.authtype == 'cut') {
            this.joincut();
        }
    },
    swiperchange: function (e) {
        this.animationaa = wx.createAnimation({
            duration: 0,
        })
        this.animationaa.opacity(0).step();
        this.setData({
            animationaa: this.animationaa.export()
        })

        this.animationaa = wx.createAnimation({
            duration: 2000,
        })
        this.animationaa.opacity(1).step();
        this.setData({
            //输出动画
            animationaa: this.animationaa.export()
        })
    },
    joincart() {
        var self = this;
        if (self.data.good.isinsever == 0) {
            app.com.toast('不在销售范围内');
            return false;
        }
        if (self.data.good.isrule == 1) {
            self.setData({
                showrule: true,
                showruletype: 'cart',
            });
        } else {
            self.incart();
        }
        self.subMess();
    },
    incart() {
        var self = this;
        var postdata = {
            op: 'add',
            id: self.data.good.id,
            num: self.data.buynum,
            mapid: self.data.actmap ? self.data.actmap : 0,
            mapname: self.data.mapname ? self.data.mapname : 0,
        };

        app.com.http('cart', 'POST', postdata, 0, true, '', '', function (res) {
            app.com.toast(res.data.message);
            if (!res.data.errno && res.data) {
                self.setData({
                    showrule: false,
                    'params.cartnum': res.data.data.nownum
                })
            }
        });
    },
    confirmcart() {
        this.incart();
    },
    playbg() {
        var self = this;
        if (self.data.bgmusic) {
            self.data.bgmusic.destroy();
        }
        self.data.bgmusic = wx.createInnerAudioContext();
        self.data.bgmusic.autoplay = true;
        self.data.bgmusic.loop = true;
        self.data.bgmusic.src = self.data.good.music;
        self.data.bgmusic.play();
        self.setData({
            audioplaying: true
        });
    },
    replaybg(type) {
        var self = this;
        if (type == 1) {
            self.setData({
                audioplaying: true,
            });
            self.data.bgmusic.play();
        } else if (type == 2) {
            self.setData({
                audioplaying: false,
            });
            self.data.bgmusic.pause();
        } else {
            self.setData({
                audioplaying: !self.data.audioplaying,
                closebg: !self.data.closebg,
            });
            if (self.data.audioplaying) {
                self.data.bgmusic.play();
            } else {
                self.data.bgmusic.pause();
            }
        }
    },
    playvideo() {
        if (this.data.VideoContext) {
            var video = this.data.VideoContext;
        } else {
            var video = this.data.VideoContext = wx.createVideoContext('videoid');
        }
        video.play()
        this.setData({
            iconPlayShow: false,
            playing: true,
        })
    },
    pauseVideo() {
        if (this.data.VideoContext) {
            var video = this.data.VideoContext;
        } else {
            var video = this.data.VideoContext = wx.createVideoContext('videoid');
        }

        if (this.data.playing) {
            video.pause()
            var iconPlayShow = true
        } else {
            video.play()
            var iconPlayShow = false
        }
        this.setData({
            iconPlayShow: iconPlayShow,
            playing: !this.data.playing,
        })
    },
    vChange(e) {
        this.setData({
            currentSwiper: e.detail.current
        })
    },
    selecttc(e) {
        if (this.data.good.getnum > 0) {
            var index = e.currentTarget.dataset.i;
            var ischecked = this.data.goodpak[index].checked;
            if (!ischecked) {
                var acted = 0;
                for (var i = 0; i < this.data.goodpak.length; i++) {
                    if (this.data.goodpak[i].checked == 1) {
                        acted++;
                    }
                }
                if (acted >= this.data.good.getnum) {
                    app.com.toast('最多选择' + this.data.good.getnum + '件');
                    return false;
                }
            }
            this.setData({
                ['goodpak[' + index + '].checked']: ischecked == 1 ? 0 : 1,
            });
        }
    },
    confirmtc() {
        var self = this;
        var pidarr = [];

        for (var i = 0; i < self.data.goodpak.length; i++) {
            if (self.data.goodpak[i].checked == 1) {
                pidarr.push(self.data.goodpak[i].gid);
            }
        }
        if (pidarr.length != self.data.good.getnum) {
            app.com.toast('需要任选' + self.data.good.getnum + '件');
            return false;
        }
        wx.setStorageSync('tclist', pidarr);
        this.setData({
            showgetnum: false,
        })
        var tourl = '/zofui_sales/order/confirm';
        wx.navigateTo({
            url: tourl
        });
    },
    stopswiper() {
        this.setData({
            autoplay: false,
        })
    },
    showtags() {
        this.setData({
            isshowtags: !this.data.isshowtags,
        })
    },
    changestatus(e) {
        var key = e.currentTarget.dataset.type;
        this.setData({
            [`${key}`]: !this.data[`${key}`],
        })
    },
    copy(e) {
        app.com.copy(e);
    },
    subMess() {
        var self = this;
        if (wx.requestSubscribeMessage) {
            wx.requestSubscribeMessage({
                tmplIds: self.data.params.submess,
                complete: function () {}
            })
        }
    },
    scrolltab(e) {
        this.setData({
            isStick: e.detail.isFixed
        })
    },
    zanit(e) {
        var self = this;
        var index = e.currentTarget.dataset.index;
        var postdata = {
            op: 'favorclick',
            cid: e.currentTarget.dataset.cid,
        };
        app.com.http('comm', 'POST', postdata, 0, true, '', '', function (res) {
            if (!res.data.errno && res.data) {
                self.setData({
                    ['comment[' + index + '].zan']: self.data.comment[index].zan * 1 + 1,
                });
                app.com.toast('点赞成功');
            } else {
                app.com.toast(res.data.message);
            }
        });
    },
    morefxrank() {
        var self = this;
        var postdata = {
            op: 'morefxrank',
            gid: self.data.good.id,
            page: self.data.rankpage,
        };
        app.com.http('good_v1', 'POST', postdata, 0, true, '', '', function (res) {
            if (!res.data.errno && res.data) {
                self.setData({
                    fxrank: self.data.fxrank.concat(res.data.data.list),
                    rankpage: self.data.rankpage + 1,
                });
            } else {
                app.com.toast(res.data.message);
            }
        });
    },
    onPageScroll(e) {
        this.data.sctop = e.scrollTop;
    },
    hideredbag() {
        this.setData({
            isshowredbag: false,
        })
    },
    showgivecard() {
        this.setData({
            isshowgivecard: !this.data.isshowgivecard
        })
    },
    changebuynum(e) {
        this.setData({
            buynum: e.detail
        })
    },
    showgifact() {
        this.setData({
            isshowifact: !this.data.isshowifact,
        })
    },
    showgifaic() {
        this.setData({
            isshowific: !this.data.isshowific,
        })
    },

})